package com.hsc.yalebao.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.model.ChatMsgEntity;
import com.hsc.yalebao.weight.LogUtils;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper
{
  public static final String CACHE_DIR;
  public static final String CACHE_DIR_DB;
  public static final String CACHE_DIR_DOWNLOAD;
  public static final String CACHE_DIR_IMAGE;
  public static final String CACHE_DIR_LOG;
  public static final String CACHE_DIR_MAPPKGS;
  public static final String CACHE_DIR_SOUND;
  public static final String DATABASE_NAME;
  public static final String DATABASE_PATH;
  public static final int DATABASE_VERSION = 1;
  public static final String REPORT_FORM;
  public static final String TABLE_NAME = "ChatMsgEntity";
  private static String TAG;
  public static String appName = "yalebao";
  private static DatabaseHelper instance;
  static Boolean isFirstRun;
  public static Boolean isFirstRunForApplication;

  static
  {
    DATABASE_PATH = CustomApplication.app.getFilesDir() + "/" + appName + ".db";
    TAG = "==DatabaseHelper==";
    isFirstRun = Boolean.valueOf(false);
    isFirstRunForApplication = Boolean.valueOf(false);
    if ("mounted".equals(Environment.getExternalStorageState()))
      CACHE_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + appName;
    while (true)
    {
      CACHE_DIR_DB = CACHE_DIR + "/db";
      CACHE_DIR_DOWNLOAD = CACHE_DIR + "/download";
      CACHE_DIR_IMAGE = CACHE_DIR + "/image";
      DATABASE_NAME = CACHE_DIR_DB + "/" + appName + ".db";
      REPORT_FORM = CACHE_DIR + "/ReportForm";
      CACHE_DIR_LOG = CACHE_DIR + "/log";
      CACHE_DIR_SOUND = CACHE_DIR + "/rec";
      CACHE_DIR_MAPPKGS = CACHE_DIR + "/mapPkgs";
      File localFile1 = new File(CACHE_DIR);
      if (!localFile1.exists())
        localFile1.mkdirs();
      File localFile2 = new File(DATABASE_NAME);
      if (!localFile2.exists());
      try
      {
        localFile2.createNewFile();
        File localFile3 = new File(CACHE_DIR_LOG);
        if (!localFile3.exists())
          localFile3.mkdirs();
        File localFile4 = new File(CACHE_DIR_DB);
        if (!localFile4.exists())
          localFile4.mkdirs();
        File localFile5 = new File(CACHE_DIR_SOUND);
        if (!localFile5.exists())
          localFile5.mkdirs();
        File localFile6 = new File(CACHE_DIR_DOWNLOAD);
        if (!localFile6.exists())
          localFile6.mkdirs();
        File localFile7 = new File(CACHE_DIR_IMAGE);
        if (!localFile7.exists())
          localFile7.mkdirs();
        File localFile8 = new File(REPORT_FORM);
        if (!localFile8.exists())
          localFile8.mkdirs();
        File localFile9 = new File(CACHE_DIR_MAPPKGS);
        if (!localFile9.exists())
          localFile9.mkdirs();
        if (!new File(DATABASE_NAME).exists())
        {
          isFirstRun = Boolean.valueOf(true);
          isFirstRunForApplication = Boolean.valueOf(true);
          return;
          CACHE_DIR = Environment.getRootDirectory().getAbsolutePath() + "/" + appName;
        }
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
        isFirstRun = Boolean.valueOf(false);
        isFirstRunForApplication = Boolean.valueOf(false);
      }
    }
  }

  public DatabaseHelper(Context paramContext)
  {
    super(paramContext, appName + ".db", null, 1);
  }

  public static DatabaseHelper getHelper(Context paramContext)
  {
    try
    {
      if (instance == null);
      try
      {
        if (instance == null)
          instance = new DatabaseHelper(paramContext);
        DatabaseHelper localDatabaseHelper = instance;
        return localDatabaseHelper;
      }
      finally
      {
      }
    }
    finally
    {
    }
  }

  public void close()
  {
    super.close();
  }

  public void onCreate(SQLiteDatabase paramSQLiteDatabase, ConnectionSource paramConnectionSource)
  {
    if (isFirstRun.booleanValue())
      LogUtils.v(TAG + "--onCreate()", "程序是第一次运行");
    try
    {
      while (true)
      {
        TableUtils.createTable(paramConnectionSource, ChatMsgEntity.class);
        return;
        LogUtils.v(TAG + "SQLConnection--onCreate()", "程序不是第一次运行");
      }
    }
    catch (SQLException localSQLException)
    {
      localSQLException.printStackTrace();
    }
  }

  public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, ConnectionSource paramConnectionSource, int paramInt1, int paramInt2)
  {
    LogUtils.d(TAG, "Upgrading database from version " + paramInt1 + " to " + paramInt2 + ".");
    switch (paramInt2)
    {
    case 1:
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.db.DatabaseHelper
 * JD-Core Version:    0.6.2
 */